package xyz.molzhao.alink.exception;

import lombok.Getter;
import xyz.molzhao.alink.base.ResultEnum;

import java.util.Objects;

/**
 * @ClassName BusinessException
 * @Description 业务异常
 * @Author MolZhao
 * @Date 2021/8/18 10:21
 * @Version v1.0
 */
public class BusinessException extends RuntimeException {
    private static final long serialVersionUID = 7799116654610030850L;

    @Getter
    private final String code;

    public BusinessException(String message) {
        super(message);
        this.code = ResultEnum.ERROR.getCode();
    }

    public BusinessException(Exception e) {
        this(e.getMessage());
    }

    public BusinessException(ResultEnum resultEnum) {
        this(resultEnum.getCode(), resultEnum.getDescription());
    }

    public BusinessException(String code, String message) {
        super(message);
        if (Objects.isNull(code)) {
            code = ResultEnum.ERROR.getCode();
        }
        this.code = code;
    }
}

